/**
 * 订单管理 交易订单
 */
<template>
    <div>
        <!-- 面包屑导航 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>公司资质审核</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 搜索筛选 -->
        <el-form :inline="true" :model="formInline" class="user-search">
            <el-form-item label="搜索：">
                <el-input
                    size="small"
                    v-model="formInline.name"
                    placeholder="公司名称"
                ></el-input>
            </el-form-item>
            <el-form-item>
                <el-button
                    size="small"
                    type="primary"
                    icon="el-icon-search"
                    @click="search"
                    >搜索</el-button
                >
            </el-form-item>
        </el-form>
        <!--列表-->
        <el-table
            size="small"
            :data="listData"
            highlight-current-row
            v-loading="loading"
            border
            element-loading-text="拼命加载中"
            style="width: 100%"
        >
            <el-table-column fixed align="center" label="序号" width="100">
                <template slot-scope="scope">
                    {{
                        scope.$index +
                        (pageparm.currentPage - 1) * pageparm.pageSize +
                        1
                    }}
                </template>
            </el-table-column>
            <el-table-column
                prop="username"
                label="公司名称"
                align="center"
                min-width="120"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="role"
                label="公司介绍"
                align="center"
                min-width="180"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="image"
                align="center"
                label="公司资质"
                min-width="120"
                show-overflow-tooltip
            >
                <template slot-scope="scope">
                    <el-image
                        style="width: 100px; height: 100px"
                        :src="scope.row.image"
                        :preview-src-list="srcList"
                        :initial-index="1"
                    >
                    </el-image>
                </template>
            </el-table-column>

            <el-table-column
                sortable
                prop="createTime"
                label="创建时间"
                align="center"
                width="180"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                align="center"
                label="操作"
                width="200"
                fixed="right"
            >
                <template slot-scope="scope">
                    <!-- <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">预览</el-button> -->
                    <el-button
                        size="mini"
                        type="primary"
                        v-if="scope.row.unitStatus == 2"
                        @click="adopt(scope.row)"
                        >通过</el-button
                    >
                    <el-button
                        size="mini"
                        type="success"
                        v-if="scope.row.unitStatus == 1"
                        >已通过</el-button
                    >
                    <el-button
                        size="mini"
                        type="info"
                        v-if="scope.row.unitStatus == 0"
                        >未通过</el-button
                    >
                    <el-button
                        size="mini"
                        type="danger"
                        v-if="scope.row.unitStatus == 2"
                        @click="fail(scope.row)"
                        >不通过</el-button
                    >
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <Pagination
            v-bind:child-msg="pageparm"
            @callFather="callFather"
        ></Pagination>
    </div>
</template>

<script>
import Pagination from "../../components/Pagination";
import moment from "moment";
import requet from "@/api/axios.js";

export default {
    data() {
        return {
            loading: false, //是显示加载
            editFormVisible: false, //控制编辑页面显示与隐藏
            formInline: {},
            srcList: [],
            listData: [], //用户数据
            // 分页参数
            pageparm: {
                currentPage: 1,
                pageSize: 10,
                total: 10,
            },
        };
    },
    // 注册组件
    components: {
        Pagination,
    },
    created() {
        this.getdata(this.pageparm.currentPage, this.pageparm.pageSize);
    },

    /**
     * 里面的方法只有被调用才会执行
     */
    methods: {
        //获取数据
        getdata(currentPage, pageSize) {
            this.loading = true;
            requet
                .get(
                    `/hkrc/unit/getUnitList?pageNo=${currentPage}&pageSize=${pageSize}`
                )
                .then((res) => {
                    console.log(res.data);
                    this.srcList = []
                    this.pageparm.total = res.data.count;
                    if (res.data.unitList.length > 0) {
                        res.data.unitList.forEach((item) => {
                            item.createTime = moment(item.createTime).format(
                                "YYYY-MM-DD hh:mm:ss"
                            );
                            this.srcList.push(item.image);
                        });

                        this.listData = res.data.unitList;
                    }
                });
            this.loading = false;
        },
        // 分页插件事件
        callFather(parm) {
            this.pageparm.currentPage = parm.currentPage;
            this.pageparm.pageSize = parm.pageSize;
            if (this.formInline.name) {
                this.search(
                    this.formInline.name,
                    this.pageparm.currentPage,
                    this.pageparm.pageSize
                );
            } else {
            this.getdata(this.pageparm.currentPage, this.pageparm.pageSize);
            }
        },
        // 搜索事件
        search() {
            this.getdata(this.pageparm.currentPage, this.pageparm.pageSize);
        },
        //通过
        adopt(data) {
            console.log(data);
            this.$confirm("确定要通过吗?", "信息", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    requet
                        .post(
                            `/hkrc/unit/verifyUnit?unitId=${
                                data.uuid
                            }&unitStatus=${1}`
                        )
                        .then((res) => {
                            console.log(res);
                            this.getdata(
                                this.pageparm.currentPage,
                                this.pageparm.pageSize
                            );
                        });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "取消",
                    });
                });
        },
        //不通过
        fail(data) {
            this.$confirm("确定要未通过吗?", "信息", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    requet
                        .post(
                            `/hkrc/unit/verifyUnit?unitId=${
                                data.uuid
                            }&unitStatus=${0}`
                        )
                        .then((res) => {
                            console.log(res);
                            this.getdata(
                                this.pageparm.currentPage,
                                this.pageparm.pageSize
                            );
                        });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "取消",
                    });
                });
        },
    },
};
</script>

<style scoped>
.user-search {
    margin-top: 20px;
}
.userRole {
    width: 100%;
}
</style>

 
 

 